﻿#include "stdafx.h"
#include "../stdafx.h"
#include "EAtmCommonFunction.h"


#include <locale>  //setlocale 解决 UNICODE字符集下CStdioFile的Writestring有无法写入中文的问题
//另外还有一种方法就是重新写CStdioFile的派生类CStdioFileEx

#include<atlconv.h>

#include "comutil.h"

EAtmCommonFunction::EAtmCommonFunction()
{
	//CoInitializeEx(NULL, COINIT_MULTITHREADED);
	MachineNumFlag = 1;   //默认操作 一台机床 (即蔡司检测机床)
	unsigned short h[3] = { 0 };

	nFlagOfStartCNC[0] = -1;
	nFlagOfStartCNC[1] = -1;
	nFlagOfStartCNC[2] = -1;

	h1[3] = { 0 };
	state[0] = 0;
	state[1] = 0;
	state[2] = 0;

	lastTask = { 0 };

	int finishIndex[2] = { 0 };
	stInfoOfElec_t currentFinishElec[2] = { 0 };

	cli_sock = 0; //和plc的连接句柄
	isRead = false;
}


EAtmCommonFunction::~EAtmCommonFunction()
{
}

//得到当前系统时间 返回一个 CString 字符串
CString EAtmCommonFunction::GetNowTime()
{
	//方法一
	time_t time_seconds = time(0);
	struct tm now_time;
	localtime_s(&now_time, &time_seconds);
	TCHAR tmp[64] = _T("");
	_tcsftime(tmp, sizeof(tmp), _T("      %Y/%m/%d %X %A"), &now_time); //_tcsftime 按自定义格式 转换系统时间函数

	CTime tm;
	tm = CTime::GetCurrentTime();

	CString m_Dayofweek = _T("");
	switch (tm.GetDayOfWeek() - 1)
	{
	case 0:m_Dayofweek = "星期日"; break;
	case 1:m_Dayofweek = "星期一"; break;
	case 2:m_Dayofweek = "星期二"; break;
	case 3:m_Dayofweek = "星期三"; break;
	case 4:m_Dayofweek = "星期四"; break;
	case 5:m_Dayofweek = "星期五"; break;
	case 6:m_Dayofweek = "星期六"; break;
	};

	CString str = tm.Format(_T("      %Y年%m月%d日 %X ")); // %A 得到英文的星期
	str += m_Dayofweek;

	return str;
}

//获取当前应用程序工作目录(exe所在目录)
CString EAtmCommonFunction::GetWorkDir()
{
	HMODULE module = GetModuleHandle(0);
	TCHAR pFileName[MAX_PATH];
	GetModuleFileName(module, pFileName, MAX_PATH);

	CString csFullPath(pFileName);
	int nPos = csFullPath.ReverseFind(_T('\\'));
	if (nPos < 0)
		return CString("");
	else
		return csFullPath.Left(nPos);
}

//编写日志文件
void EAtmCommonFunction::WriteLog(CString logStr)
{
	time_t time_seconds = time(0);
	struct tm now_time;
	localtime_s(&now_time, &time_seconds);
	TCHAR tmp[64] = _T("");
	_tcsftime(tmp, sizeof(tmp), _T("%Y/%m/%d %X"), &now_time); //_tcsftime 按自定义格式 转换系统时间函数
	CString logpath, logDirectory;
	logDirectory = GetWorkDir() + _T("\\EAtmLog");
	if (!(GetFileAttributes(logDirectory) == FILE_ATTRIBUTE_DIRECTORY))     //如果目标路径不存在，则创建该路径
	{
		CreateDirectory(logDirectory, NULL);
	}
	logpath = GetWorkDir() + _T("\\EAtmLog\\EAtmLog.log");
	//UNICODE字符集下CStdioFile的Writestring有无法写入中文的问题
	CStdioFile myFile;
	CFileException fileException;
	TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL));
	_tsetlocale(LC_CTYPE, _T("chs"));
	if (myFile.Open(logpath, CFile::modeCreate | CFile::modeNoTruncate | CFile::typeText | CFile::modeWrite, NULL))
	{



		myFile.SeekToEnd();
		myFile.WriteString(tmp);
		myFile.WriteString(_T(": "));

		//_tsetlocale(LC_ALL, _T("chs
		myFile.WriteString(logStr);
		myFile.WriteString(_T("\n"));
		myFile.Close();



	}
	CFileStatus status;                      //检测文件的大小是否超过10M，超过则重命名
	CFile::GetStatus(logpath, status);
	ULONGLONG size = status.m_size;
	if (size > 1024 * 1024 * 10)              //如果文件大小大于10M
	{
		CString newname;
		_tcsftime(tmp, sizeof(tmp), _T("%Y%m%d"), &now_time);
		newname.Format(_T("%s(%s).log"), logpath, tmp);
		_trename(logpath, newname);
	}
	_tsetlocale(LC_CTYPE, old_locale);
	free(old_locale);//还原区域设定
}

//从配置文件获取连接参数
CString EAtmCommonFunction::GetConnectionParameter(int parameterType)
{
	TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL)); //解决CStdioFile::ReadString 中文 在unicode下乱码
	_tsetlocale(LC_CTYPE, _T("chs"));

	CFileFind tempFind;
	CString  filePath = _T("");
	CString  connectParameter = (CString)"";

	CString logDirectory;
	logDirectory = GetWorkDir() + _T("\\ConfigurationFile");
	if (!(GetFileAttributes(logDirectory) == FILE_ATTRIBUTE_DIRECTORY))     //如果目标路径不存在，则创建该路径
	{
		CreateDirectory(logDirectory, NULL);
	}

	filePath = GetWorkDir() + _T("\\ConfigurationFile\\ConnectionConfig.ini");
	BOOL IsFinded = (BOOL)tempFind.FindFile(filePath);
	if (IsFinded) //如果配置文件存在
	{
		CStdioFile myFile;
		if (myFile.Open(filePath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite | CFile::typeText, NULL))
		{
			CString strContent = (CString)"";
			if (parameterType == DATABASECONNECTION)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("DataBaseConnectionString")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, ':');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("\nDataBaseConnectionString:Provider=OraOLEDB.Oracle;User ID=eatm;Password=123;Persist Security Info=False;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));"));
					connectParameter = _T("Provider=OraOLEDB.Oracle;User ID=eatm;Password=123;Persist Security Info=False;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.54.1.253)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl.54.1.30)));");
				}
			}
			else if (parameterType == COMPORT)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("ComPort")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("\nComPort=3"));
					connectParameter = "3";
				}
			}
			else if (parameterType == PLCIP)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("PLCIP")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("\nPLCIP=192.168.1.10"));
					connectParameter = "192.168.1.10";
				}
			}
			else if (parameterType == ROBERTIP)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("RobertIP")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("\nRobertIP=192.168.1.7"));  //机器人IP
					connectParameter = "192.168.1.7";
				}
			}
			else if (parameterType == XMLFILEPATH)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("xml文档路径")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("\nxml文档路径=D:\\Zeiss\\FACS\\CONF\\FACSConf_Basic.xml"));
					connectParameter = _T("D:\\Zeiss\\FACS\\CONF\\FACSConf_Basic.xml");
				}
			}
			else if (parameterType == INSPECTIONROOTDIRECTORY)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("程式主目录")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					//myFile.WriteString(_T("\n程式主目录=C:\\Users\\EAtm\\Desktop\\ZEISS\\Files"));
					//connectParameter = _T("C:\\Users\\EAtm\\Desktop\\ZEISS\\Files");
					myFile.WriteString(_T("\n程式主目录=D:\\AT\\Allgemein"));
					connectParameter = _T("D:\\AT\\Allgemein");
				}
			}
			else if (parameterType == COMPORT)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("ComPort")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("\nComPort=3"));
					connectParameter = "3";
				}
			}
			else if (parameterType == BAUDRATE)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("Baudrate")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("\nBaudrate=115200"));
					connectParameter = "115200";
				}
			}
			else if (parameterType == PRGFACTORYPATH)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("PRGFACTORYPath")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("\nPRGFACTORYPath=C:\\Program Files\\CMMAUTO\\Stanley studio\\PRGFactory\\PRGFactory.exe"));
					connectParameter = "C:\\Program Files\\CMMAUTO\\Stanley studio\\PRGFactory\\PRGFactory.exe";
				}
			}
			else if (parameterType == CMMTIMEOUT)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("TimeOut")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("\nTimeOut=5min5s"));
					connectParameter = "10min0s";
				}
			}
			else if (parameterType == FANUC01IP)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("FANUC01IP")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("FANUC01IP=192.168.200.104"));
					connectParameter = "192.168.200.104";
				}
			}
			else if (parameterType == FANUC02IP)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("FANUC02IP")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("FANUC02IP=192.168.201.212\n"));
					connectParameter = "192.168.201.212";
				}
			}
			else if (parameterType == FANUC03IP)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("FANUC03IP")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("FANUC03IP=192.168.200.102"));
					connectParameter = "192.168.200.102";
				}
			}
			else if (parameterType == FANUCPORT)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("FanucPort")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("FanucPort=8193"));
					connectParameter = "8193";
				}
			}
			else if (parameterType == RFIDIP)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("rfidIP")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("rfidIP=192.168.201.11"));
					connectParameter = "192.168.201.11";
				}
			}
			else if (parameterType == RFIDPORT)
			{
				int count = 0;
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("rfidIPort")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						connectParameter = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (connectParameter == "")
				{
					myFile.SeekToEnd();
					myFile.WriteString(_T("rfidIPort=7090"));
					connectParameter = "7090";
				}
			}
			else
			{
				WriteLog(_T("打开连接配置文件出错"));
			}

		}
		else
		{
			WriteLog(_T("打开连接配置文件出错"));
		}
	}
	else
	{

		CStdioFile myFile;
		if (myFile.Open(filePath, CFile::modeCreate | CFile::modeNoTruncate | CFile::typeText | CFile::modeReadWrite, NULL))
		{
			if (parameterType == DATABASECONNECTION)
			{
				myFile.SeekToEnd();
				myFile.WriteString(_T("\nDataBaseConnectionString:Provider=OraOLEDB.Oracle;User ID=eatm;Password=123;Persist Security Info=False;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));"));
				connectParameter = _T("Provider=OraOLEDB.Oracle;User ID=eatm;Password=123;Persist Security Info=False;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));");
			}
			else if (parameterType == COMPORT)
			{
				myFile.SeekToEnd();
				myFile.WriteString(_T("\nComPort=3"));
				connectParameter = "3";
			}
			else if (parameterType == PLCIP)
			{
				myFile.SeekToEnd();
				myFile.WriteString(_T("\nPLCIP=192.168.1.10"));
				connectParameter = "192.168.1.10";
			}
			else if (parameterType == ROBERTIP)
			{
				myFile.SeekToEnd();
				myFile.WriteString(_T("\nRobertIP=192.168.1.7"));
				connectParameter = "192.168.1.7";
			}
			else if (parameterType == XMLFILEPATH)
			{
				myFile.SeekToEnd();
				myFile.WriteString(_T("\nxml文档路径=D:\\Zeiss\\FACS\\CONF\\FACSConf_Basic.xml"));
				connectParameter = "D:\\Zeiss\\FACS\\CONF\\FACSConf_Basic.xml";
			}
			else if (parameterType == INSPECTIONROOTDIRECTORY)
			{
				myFile.SeekToEnd();
				myFile.WriteString(_T("\n程式主目录=C:\\Users\\EAtm\\Desktop\\ZEISS\\Files"));
				connectParameter = "C:\\Users\\EAtm\\Desktop\\ZEISS\\Files";
			}
			myFile.Close();
		}
	}
	_tsetlocale(LC_CTYPE, old_locale);
	free(old_locale);//还原区域设定
	return connectParameter;
}



//根据数据库中存在的用户名和密码进行 登陆验证//根据数据库中存在的用户名和密码进行 登陆验证
int EAtmCommonFunction::DataBaseCheckUser(CString strUser, CString &strPassword)
{
	int irc = 0;
	BOOL retFt = false;
	_ConnectionPtr m_pConnection;
	_RecordsetPtr m_pRecordset;
	HRESULT hr;
	CString strSql;
	strSql.Format(_T("select * from t_UserList where upper(UserName) = upper('%s')"), strUser);
	//strSql.Format(_T("select * from t_preparematerial where upper(fixtureno) = upper('%s') order by AddTime desc"), strUser);
	try
	{

		hr = m_pConnection.CreateInstance(_uuidof(Connection));///创建Connection对象


															   //hr1 = m_pRecordset.CreateInstance(__uuidof(Recordset));
		if (SUCCEEDED(hr))
		{

			_bstr_t connStr;


			m_pConnection->CursorLocation = adUseClient;

			//begin---------------Oracle 标准安全级别---------------------------------------
			connStr = GetConnectionParameter(DATABASECONNECTION);

			//connStr = "Provider=OraOLEDB.Oracle;User ID=eatm;Password=123;Persist Security Info=False;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));";


			m_pConnection->Open((_bstr_t)(connStr), (_bstr_t)_T(""), (_bstr_t)_T(""), adConnectUnspecified);

			//end---------------Oracle 标准安全级别---------------------------------------
		}


	}
	catch (_com_error e)///捕捉异常
	{
		retFt = false;

		//MessageBox(NULL,e.ErrorMessage(),"连接数据库出错",MB_OK);
		return 1;
	}
	//连接到数据库后，开始执行SQL语句
	if ((m_pRecordset.CreateInstance(__uuidof(Recordset))))
	{
		//MessageBox(NULL,"记录集对象指针实例化失败","message",MB_OK);
		return 1;
	}
	try
	{
		m_pRecordset->Open((_variant_t)strSql,
			m_pConnection.GetInterfacePtr(),
			adOpenDynamic,
			adLockOptimistic, adCmdText);//打开数据库，执行SQL语句
	}
	catch (_com_error e)
	{
		//MessageBox(NULL,e.ErrorMessage(),"打开记录集出错",MB_OK);

		return 1;
	}
	try
	{
		if (m_pRecordset->_EOF == VARIANT_TRUE) //如果没查到数据
			return 2;
		CString strStr = (_bstr_t)m_pRecordset->GetCollect(_T("PASSWORD"));
		strPassword = strStr;
	}
	catch (_com_error e)
	{

		return 1;
	}
	m_pRecordset->Close();      // 关闭记录集
	m_pRecordset = NULL;
	if (m_pConnection->State)
		m_pConnection->Close();   //关闭连接对象
	m_pConnection = NULL;
	return irc;
}



CString EAtmCommonFunction::GetPath(int PathType)
{
	CFileFind tempFind;
	CString  filePath = _T(""); //配置文件路径
	CString path = (CString)"";

	if (PathType == EAtmLOGPATH)
	{
		if (GetWorkDir() + _T("\\EAtmLog\\EAtmLog.log"))
			return GetWorkDir() + _T("\\EAtmLog\\EAtmLog.log");
	}

	filePath = GetWorkDir() + _T("\\confg_data\\BasicConfig.ini");
	BOOL IsFinded = (BOOL)tempFind.FindFile(filePath);
	if (IsFinded)
	{
		CStdioFile myFile;
		//CStdioFile myFile(fopen(filePath,"a+,ccs=UNICODE")); 
		if (myFile.Open(filePath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeReadWrite | CFile::typeText, NULL))
		{
			CString strContent = _T("");
			strContent.Format(_T(""));
			if (PathType == REPORTPATH)
			{
				int count = 0;
				path.Format(_T(""));
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("结果文件存放路径")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						path = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (path == "")
				{
					myFile.SeekToEnd();
					path = _T("D:\\CMM\\REPORT");
					myFile.WriteString(_T("\n结果文件存放路径=D:\\CMM\\REPORT"));
				}
			}
			else if (PathType == COPYREPORTPATH)
			{
				int count = 0;
				path.Format(_T(""));
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("结果文件拷贝路径")) != -1)
					{
						CString strtemp = _T("");
						AfxExtractSubString(strtemp, strContent, 1, '=');
						path = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (path == "")
				{
					myFile.SeekToEnd();
					path = _T("\\\\10.54.1.27\\cmm_file");
					myFile.WriteString(_T("\n结果文件拷贝路径=\\\\10.54.1.27\\cmm_file"));
				}
			}
			else if (PathType == VPDPATH)
			{
				int count = 0;
				path.Format(_T(""));
				while (myFile.ReadString(strContent))
				{
					count++;
					if (strContent.Find(_T("VPD文件存放路径")) != -1)
					{
						CString strtemp;
						AfxExtractSubString(strtemp, strContent, 1, '=');
						path = strtemp;
						break;
					}
					if (count > 100)      //不能正常读到文件尾，读到第100次时强制跳出
					{
						break;
					}
				}
				if (path == "")
				{
					myFile.SeekToEnd();//将文件指针移动到文件末尾。返回值是文件的字节长度。它等价于CFile::Seek(0L, CFile::end
					path = _T("D:\\CMM\\VPD");
					myFile.WriteString(_T("\nVPD文件存放路径=D:\\CMM\\VPD"));//在文件末尾追加此句
				}
			}
			myFile.Close();
		}
	}
	else
	{
		CStdioFile myFile;
		if (myFile.Open(filePath, CFile::modeCreate | CFile::modeNoTruncate | CFile::typeText | CFile::modeReadWrite, NULL))
		{
			if (PathType == REPORTPATH)
			{
				myFile.SeekToEnd();
				path = "D:\\CMM\\REPORT";
				myFile.WriteString(_T("\n结果文件存放路径=D:\\CMM\\REPORT"));
			}
			else if (PathType == COPYREPORTPATH)
			{
				myFile.SeekToEnd();
				path = "\\\\10.54.1.27\\cmm_file";
				myFile.WriteString(_T("\n结果文件拷贝路径=\\\\10.54.1.27\\cmm_file"));
			}
			else if (PathType == VPDPATH)
			{
				myFile.SeekToEnd();
				path = "D:\\CMM\\VPD";
				myFile.WriteString(_T("\nVPD文件存放路径=D:\\CMM\\VPD"));
			}
			myFile.Close();
		}
	}
	return path;

}

//建立客户端  根据参数 选择 需要连接 那个服务器 如PLC 如 机器人
bool EAtmCommonFunction::CreateClient(int ConnectionType)
{
	//建立客户端

	if (ConnectionType == PLCIP)
	{
		//方法一
		//CString serverIp = GetConnectionParameter(ConnectionType);

		//CString serverIp = _T("127.0.0.1");
		//int port = 502;
		//
		//pMysocket = new CSocket;
		//if (!pMysocket->Create()) //创建套接字 ,需要 在初始化  中 执行AfxSocketInit();
		//{
		//	delete pMysocket;
		//	pMysocket = NULL;
		//	EAtm.WriteLog(_T("套接字创建失败"));
		//	return false;
		//}
		//if (!pMysocket->Connect(serverIp, port)) //连接服务器
		//{
		//	EAtm.WriteLog(_T("连接服务器失败"));
		//	return false;
		//}

		//EAtm.WriteLog(_T("连接服务器成功"));
		//return true;

		//方法二
		//CString ipaddress = _T("127.0.0.1");
		CString ipaddress = GetConnectionParameter(PLCIP);
		InetPton(AF_INET, ipaddress, (void*)&cli.sin_addr.s_addr); //代替 cli.sin_addr.s_addr = inet_addr(const char *);     //设置客户端地址  建议使用这个 而不是 inet_pton #include "Ws2tcpip.h"
																   //inet_pton(AF_INET, ipaddress, (void*)&cli.sin_addr.s_addr); //#include "Ws2tcpip.h"  这个也可以 但是在unicode下 ipaddress 需要类型转换
		cli.sin_family = AF_INET;
		cli.sin_port = htons(502);											      //设置端口号
		cli_sock = socket(AF_INET, SOCK_STREAM, 0);								  //创建socket
		if (connect(cli_sock, (sockaddr*)&(cli), sizeof(cli)) == SOCKET_ERROR)       //连接到服务器
		{
			cli_sock = 0;
			WriteLog(_T("连接PLC服务器失败"));
			return false;
		}
		else
		{
			WriteLog(_T("连接PLC服务器成功"));
			return true;
		}
	}
	else if (ConnectionType == FacsIP)
	{
		CString strFacsIp = _T("192.168.1.33"); //TCP版本 facs 一般装在本机
		int iFacsPort = 6626;               //此端口可以在 facs的配置文件里设置

											//构建服务器地址信息  
		struct sockaddr_in saServer; //服务器地址信息  
		InetPton(AF_INET, strFacsIp, (void*)&saServer.sin_addr.S_un.S_addr);
		saServer.sin_family = AF_INET; //地址家族  这一句不能省 不能因为InetPton第一个参数有就不加这一句  两者没有关联
		saServer.sin_port = htons(iFacsPort); //注意转化为网络节序  

		//	m_hClient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);   //创建客户端类型socket 
		m_hClient = socket(AF_INET, SOCK_STREAM, 0);  //上面是老陈的 ,现在改成这个
		if (m_hClient == INVALID_SOCKET)  //如果 是 无效套接字
		{
			m_bConnect = FALSE;
			return FALSE;
		}

		//连接服务器  
		int ret = connect(m_hClient, (struct sockaddr *)&saServer, sizeof(saServer));
		if (ret == SOCKET_ERROR)
		{
			m_hClient = 0;
			WriteLog(_T("连接FACS服务器失败"));
			m_bConnect = FALSE;
			return FALSE;
		}
		else
		{
			WriteLog(_T("连接FACS服务器成功"));
			m_bConnect = TRUE;
			return true;
		}


	}
	else if (ConnectionType == RFIDIP)
	{
		CString ipaddress = GetConnectionParameter(RFIDIP);
		InetPton(AF_INET, ipaddress, (void*)&cli.sin_addr.s_addr); //代替 cli.sin_addr.s_addr = inet_addr(const char *);     //设置客户端地址  建议使用这个 而不是 inet_pton #include "Ws2tcpip.h"
																   //inet_pton(AF_INET, ipaddress, (void*)&cli.sin_addr.s_addr); //#include "Ws2tcpip.h"  这个也可以 但是在unicode下 ipaddress 需要类型转换
		cli.sin_family = AF_INET;
		cli.sin_port = htons(10001);											         //设置端口号
		rdif_cli_sock = socket(AF_INET, SOCK_STREAM, 0);								  //创建socket
		if (connect(rdif_cli_sock, (sockaddr*)&(cli), sizeof(cli)) == SOCKET_ERROR)       //连接到服务器
		{
			rdif_cli_sock = 0;
			WriteLog(_T("连接rfid失败"));
			return false;
		}
		else
		{
			WriteLog(_T("连接rdif成功"));
			return true;
		}
	}
	else
		return false;
}

//连接FANUC机床
int EAtmCommonFunction::ConnectCNC(int parameterType, unsigned short* handle)
{
	CString ipaddress = GetConnectionParameter(parameterType);
	int FANUC01Port = 8193;

	USES_CONVERSION;
	char* ip = T2A(ipaddress.GetBuffer(ipaddress.GetLength()));



	//int ret = cnc_allclibhndl3(ip, FANUC01Port, 10, handle);//会卡在这卡,  宽字节的CString 和 参数要求的多字节 const char* 冲突

	return 0;
}
//加载检测程序
bool EAtmCommonFunction::LoadDetection(CString checkNcName)
{
	//IINSPECT>1122999888sky1test290720050819\r\n
	CTime t = CTime::GetCurrentTime(); //获取系统日期，存储在t里面	
	CString sPadding = _T("IINSPECT>1122999888");
	CString sDateTime, sData;

	int d = t.GetDay(); //获得当前日期
	int y = t.GetYear(); //获取当前年份
	int m = t.GetMonth(); //获取当前月份
	int h = t.GetHour(); //获取当前为几时
	int mm = t.GetMinute(); //获取当前分钟
	int s = t.GetSecond(); //获取当前秒
	int w = t.GetDayOfWeek(); //获取星期几，注意1为星期天，7为星期六

	sDateTime.Format(_T("%02d%02d%04d%02d%02d\r\n"), d, m, y, h, mm);
	//GetDlgItem(IDC_DETECTION_NAME)->GetWindowText(sDetection);
	sData = sPadding + checkNcName + sDateTime;

	USES_CONVERSION;
	char* msg = T2A(sData.GetBuffer(sData.GetLength()));

	//int ret = send (m_hClient, (LPSTR)(LPCTSTR)sData, sData.GetLength(), 0);   //问题处在 unicode下 (LPSTR)(LPCTSTR)sData 内容有问题,  多字节 可以直接发送 CString 没问题

	int ret = send(this->m_hClient, msg, strlen(msg), 0);
	if (ret == SOCKET_ERROR)
	{
		//AfxMessageBox(_T("send() failed!"));  
		//m_ctrlStateList.AddString(_T("加载程序失败"));
		//::SendMessage(m_hStatusWindow, SB_SETTEXT, 1, (LPARAM)TEXT("加载程序失败"));
		return FALSE;
	}


	//m_ctrlStateList.AddString(_T("正在加载检测程序"));
	//::SendMessage(m_hStatusWindow, SB_SETTEXT, 1, (LPARAM)TEXT("正在加载检测程序"));
	//::SendMessage(m_hStatusWindow,SB_SETTEXT,2,(LPARAM)TEXT("FACS客户端accept失败：14"));

	return TRUE;
}

bool EAtmCommonFunction::StartAutoCMM(CString checkNcName)
{
	bool ret1 = SwitchAutoCMM();
	if (ret1 == false)
		return FALSE;
	Sleep(300);
	bool ret2 = LoadDetection(checkNcName);
	if (ret2 == false)
		return FALSE;
	Sleep(300);
	bool ret3 = StartZEISS(); //结果会回馈到本软件创建的服务器上
	if (ret3 == false)
		return FALSE;


	return TRUE;
}

//FACS切换至自动模式
bool EAtmCommonFunction::SwitchAutoCMM()
{
	//方法一
	//CString order(FACS_AUTOMODEL);
	//int len = order.GetLength();
	//char *msg = new char[len];
	//for (int i = 0; i < len; i++)
	//	msg[i] = (char)order.GetAt(i);

	//方法二   
	USES_CONVERSION;  //要使用T2A A2W 等转化函数 必须前置次宏
	CString order(FACS_AUTOMODEL);
	char* msg = T2A(order.GetBuffer(order.GetLength()));

	//int ret = send (m_hClient, T2A(FACS_AUTOMODEL), _tcslen(FACS_AUTOMODEL), 0);  
	//这一个写法在这里完全可以 只不过 发送的是中文的时候会出现信息发送不完整 原因在于_tcslen(FACS_AUTOMODEL)中文 的字节数不符合实际, 需要乘2 
	//为了统一写法和应对各种情况 使用下面的方法

	int ret = send(m_hClient, msg, strlen(msg), 0);

	if (ret == SOCKET_ERROR)
	{
		//AfxMessageBox(_T("send() failed!"));  
		//::SendMessage(m_hStatusWindow, SB_SETTEXT, 1, (LPARAM)TEXT("切换自动失败"));
		return FALSE;
	}
	else
	{
		//::SendMessage(m_hStatusWindow, SB_SETTEXT, 1, (LPARAM)TEXT("正在切换为自动模式"));
		//::SendMessage(m_hStatusWindow,SB_SETTEXT,2,(LPARAM)TEXT("FACS客户端accept失败：14"));
	}
	return TRUE;
}

//启动机床   根据类型启动机床
bool EAtmCommonFunction::StartZEISS()
{
	USES_CONVERSION;

	CString order(FACS_START);

	char* msg = T2A(order.GetBuffer(order.GetLength()));

	//int ret = send (m_hClient, T2A(FACS_START), _tcslen(FACS_START), 0);  
	//这一个写法在这里完全可以 只不过 发送的是中文的时候会出现信息发送不完整 原因在于_tcslen(FACS_START)中文 的字节数不符合实际, 需要乘2 
	//为了统一写法和应对各种情况 使用下面的方法

	int ret = send(m_hClient, msg, strlen(msg), 0);
	if (ret == SOCKET_ERROR)
	{
		//AfxMessageBox(_T("send() failed!"));  

		return FALSE;
	}

	return TRUE;
}


//将一个字节型的8个位分离出来并保存至字节变量中
//第一个参数是输入的Byte数
//第二个参数是分离得到的字节数组
//第三个参数是想要得到的位数
bool EAtmCommonFunction::GetSensorStatus(byte* Src, _Out_ byte* Dst, int sizeDst)
{
	//解析buffer[9]和后面的 所有数据   把每个byte  分拆成8位 ,分别保存到 另一个 char status[] 的数组中 
	//将 byte类型 16进制数 转化成 2进制形式 如 0C --> 0000 1100    从又往左读  表示  11 12 号库位上 有电极 
	int j = 0;
	for (; j < sizeDst / 8; j++)
	{
		SetBytesToBits(&Src[9 + j], &Dst[j * 8], 8); //buffer[9] 开始往后 都是plc传来的 数据,  参数3是实际需要获取库位的个数
	}
	if (sizeDst % 8)													//
	{
		SetBytesToBits(&Src[9 + j], &Dst[j * 8], sizeDst - j * 8);
	}
	return true;
}

//就是传进来一个char 然后把它分拆成8位 ,分别保存到 另一个 char byteReturn[8] 的数组中 
bool EAtmCommonFunction::SetBytesToBits(byte *byteData, byte * byteReturn, int count) //将 unsigned char 类型 16进制数 转化成 2进制形式 如 char a = 100  -->  
{
	//如 byteData = 0C 等价于 0000 1100   byteReturn 是待写入的传出参数 count = 8 要获取8个库位的信息  count =1 就获取一个

	//for (int i = 7; i >= 8 - count; i--)  //循环8次
	//{
	//	byteReturn[7 - i] = (byte)(byteData & 1); //0&0=0 0&1=0 1&1=1
	//	byteData = (byte)(byteData >> 1);
	//}
	
	for (int i = 0; i < count; ++i)
	{
		byteReturn[i] = (byteData[i >> 3] >> (i & 7)) & 1;
	}
	return true;
}

//按字分解 -从低位往高位读,最多读取16位
bool EAtmCommonFunction::SetWordsToBits(const WORD* pSrc, bool* pDes, int bits)
{
	if (bits > 16) return false;

	for (int i = 0; i < bits; ++i)
		pDes[i] = (pSrc[i >> 4] >> (i & 15)) & 1; //颠倒高低字节序 只需改为 pDes[15 - i]
	
	return true;
}

bool EAtmCommonFunction::SetbitOfByte(byte *byteData, int position, bool flag)
{
	assert(byteData);
	if (position > 8 || position < 1) return false;

	if (flag != (*byteData >> (position - 1) & 1))
		*byteData ^= 1 << (position - 1);

	return true;
}

bool EAtmCommonFunction::SetbitOfWord(WORD *WordData, int position, bool flag)
{
	assert(WordData);
	if (position > 16 || position < 1) return false;

	if (flag != (*WordData >> (position - 1) & 1))
		*WordData ^= 1 << (position - 1);

	return true;
}

//向plcO点写入值，返回值0表示正常，1表示写入失败，2表示通讯处问题了
BOOL EAtmCommonFunction::writePlcRegister(WORD RegisterAddress, WORD count, WORD * valueOfRegister)
{
	if (!cli_sock) return false;
	
	int s = 0;
	BOOL irc = TRUE;
	byte buffer[255] = { 0 };
	byte *sendByte = new byte[13 + count * 2];
	byte * sendByteBak = sendByte;

	for (int i = 0; i <= 4; i++)
		*sendByte++ = 0;                // 0 0 0 0

	*sendByte++ = 7 + count * 2;      //后面跟着 9个字节
	*sendByte++ = 0;
	*sendByte++ = 0x10; //功能码 写入单个或多个寄存器
	*sendByte++ = (byte)(RegisterAddress >> 8);
	*sendByte++ = (byte)RegisterAddress;  //起始地址 
	*sendByte++ = (byte)(count >> 8);
	*sendByte++ = (byte)count; //写入数目  count =1
	*sendByte++ = 2 * count; //写入的字节数

	for (int i = 0; i < count; i++)
	{
		*sendByte++ = (byte)(*valueOfRegister >> 8);
		*sendByte++ = (byte)*valueOfRegister++;
	}
	send(cli_sock, (char *)sendByteBak, 13 + count * 2, 0);
	s = recv(cli_sock, (char *)buffer, 255, 0);     //循环接受数据
	if (s != SOCKET_ERROR)
	{
		if (buffer[7] != 16)       //如果发送帧和应答帧的功能码不一致则执行出错
		{
			WriteLog(_T("写入PLC信息出错"));
			irc = FALSE;
		}
		irc = FALSE;
	}
	delete sendByteBak;

	return irc;
}

int EAtmCommonFunction::readPlcDate(byte FunctionCode, WORD indexOfRegister, WORD count, void *valueofRegister)
{
	if (!cli_sock) return false;

	int s, irc = 0;
	byte buffer[256] = { 0 };
	//byte *sendByte = new byte[12];
	//byte * sendByteBak = sendByte;

	//for (int i = 0; i <= 4; i++)
	//	*sendByte++ = 0;                // 0 0 0 0

	//*sendByte++ = 6;      //后面跟着 9个字节
	//*sendByte++ = 0;
	//*sendByte++ = 0x3; //功能码 读取单个或多个寄存器
	//*sendByte++ = (byte)(indexOfRegister >> 8);
	//*sendByte++ = (byte)indexOfRegister;  //起始地址 
	//*sendByte++ = (byte)(count >> 8);
	//*sendByte++ = (byte)count; //读取的数目 

	//send(cli_sock, (char *)sendByteBak, 12, 0);
	//s = recv(cli_sock, (char *)buffer, 255, 0);     //循环接受数据
	
	byte sendByte[12] = { 0 };
	sendByte[5] = 6;
	sendByte[6] = 0;
	sendByte[7] = FunctionCode;				     
	sendByte[8] = (byte)(indexOfRegister >> 8);       //大于255的需要位移
	sendByte[9] = (byte)indexOfRegister;
	sendByte[10] = (byte)(count >> 8);      //此处1为寄存器的数目
	sendByte[11] = (byte)count;
	send(cli_sock, (char *)sendByte, sizeof(sendByte), 0);   //等价于 发送了 00 00 00 00 00 06 00 02 00 10 00 2E  (十六进制) 获得那些货位有电极的信息
	Sleep(100);
	s = recv(cli_sock, (char *)buffer, 255, 0);
	if (s != SOCKET_ERROR)
	{
		if (buffer[7] != FunctionCode)       //如果发送帧和应答帧的功能码不一致则执行出错
		{
			WriteLog(_T("读取寄存器信息出错"));			
			irc = 0;
		}
		else
		{
			irc = 1;
			//for (int i = 0; i < count; i++)
			//{
			//	//valueofRegister[i] = buffer[i + 10];
			//}
			if(FunctionCode == 0x3)
			{
				//CopyMemory((byte*)valueofRegister, buffer+10, 1);
				//CopyMemory((byte*)valueofRegister + 1, buffer+9, 1);
				for (int i = 0; i < count; i++)
				{
					CopyMemory((byte*)valueofRegister + i, buffer + 9 + i, 1);
					CopyMemory((byte*)valueofRegister + 1 + i, buffer + 10 + i, 1);
				}
			}
			else if(FunctionCode == 0x2)  
				CopyMemory((byte*)valueofRegister, buffer, 9 + buffer[8]);
				
		}
		

	}
	//delete sendByteBak;
	
	return irc;
}

int	EAtmCommonFunction::GetInfoForDB(CString sStrCode, stInfoOfElec_s &EleInfo)
{
#if 1
	USES_CONVERSION;  //要使用T2A A2W 等转化函数 必须前置次宏
	char* cStrCode = T2A(sStrCode.GetBuffer(sStrCode.GetLength()));

	pugi::xml_document xmlDoc;
	if (!xmlDoc.load_file(GetWorkDir() + _T("\\data\\database.xml")))
	{
		return -1;
	}

	pugi::xml_node Database = xmlDoc.child(_T("Database"));
	pugi::xml_node Info;
	for (pugi::xml_node DataItem = Database.first_child(); DataItem; DataItem = DataItem.next_sibling())
	{
		for (pugi::xml_attribute attr = DataItem.first_attribute(); attr; attr = attr.next_attribute())
		{
			if (_tcscmp(attr.name(), _T("FIXTURENO")) == 0)
			{
				if (_tcscmp(attr.value(), S_CA2W(cStrCode)) == 0)
				{
					Info = DataItem;
					goto RES_SUCCESS;
				}
			}
		}

	}
	return -2;
RES_SUCCESS:
	for (pugi::xml_attribute attr = Info.first_attribute(); attr; attr = attr.next_attribute())
	{
		STRACE(_T("\t%s=%s"), attr.name(), attr.value());
	}

	pugi::xml_attribute attr = Info.attribute(_T("MouldInteriorID"));
	_tcscpy(EleInfo.cMouldInteriorID, attr.value());

	attr = Info.attribute(_T("ELECTRODENAME"));
	_tcscpy(EleInfo.cElectrodeName, attr.value());

	attr = Info.attribute(_T("FIXTURENO"));
	_tcscpy(EleInfo.cBarcode, attr.value());

	attr = Info.attribute(_T("FIXTURETYPE"));
	_tcscpy(EleInfo.cFixtureType, attr.value());

	//attr = Info.attribute(_T("ELECNUMBER"));
	//_tcscpy(EleInfo.sElecNumber, attr.value());

	attr = Info.attribute(_T("ELECTRODETYPE"));
	_tcscpy(EleInfo.cElectrodetype, attr.value());

	attr = Info.attribute(_T("SPARK"));
	_tcscpy(EleInfo.cSpark, attr.value());

	attr = Info.attribute(_T("SPECIFICATIONS"));
	_tcscpy(EleInfo.cSpecifications, attr.value());

	EleInfo.state = 2;

	return 1;

	CString strSql = _T("");
	strSql.Format(_T("SELECT *  FROM t_preparematerial  where upper(fixtureno)=upper('%S') order by AddTime desc"), sStrCode);
#else

	//if (!m_pRs->Open(strSql))
	//{
	//	return -1;
	//}

	//CString sField = _T("MOULDINTERIORID");
	//_variant_t vtFld;

	//if (!m_pRs->GetFieldValue(sField, vtFld))
	//{
	//	return -2;
	//}
	//_tcscpy(EleInfo.sMouldInteriorID, (TCHAR*)(_bstr_t)vtFld);

	//sField = _T("ELECTRODENAME");
	//if (!m_pRs->GetFieldValue(sField, vtFld))
	//{
	//	return -2;
	//}
	//_tcscpy(EleInfo.sElectrodeName, (TCHAR*)(_bstr_t)vtFld);

	//sField = _T("FIXTURENO");
	//if (!m_pRs->GetFieldValue(sField, vtFld))
	//{
	//	return -2;
	//}
	//_tcscpy(EleInfo.sFixtureNo, (TCHAR*)(_bstr_t)vtFld);

	//sField = _T("FIXTURETYPE");
	//if (!m_pRs->GetFieldValue(sField, vtFld))
	//{
	//	return -2;
	//}
	//_tcscpy(EleInfo.sFixtureType, (TCHAR*)(_bstr_t)vtFld);

	//sField = _T("ELECNUMBER");
	//if (!m_pRs->GetFieldValue(sField, vtFld))
	//{
	//	return -2;
	//}
	//_tcscpy(EleInfo.sElecNumber, (TCHAR*)(_bstr_t)vtFld);

	//sField = _T("ELECTRODENAME");
	//if (!m_pRs->GetFieldValue(sField, vtFld))
	//{
	//	return -2;
	//}
	//_tcscpy(EleInfo.sElectrodeName, (TCHAR*)(_bstr_t)vtFld);

	//sField = _T("ELECTRODETYPE");
	//if (!m_pRs->GetFieldValue(sField, vtFld))
	//{
	//	return -2;
	//}
	//_tcscpy(EleInfo.sElectrodetype, (TCHAR*)(_bstr_t)vtFld);

	//sField = _T("SPARK");
	//if (!m_pRs->GetFieldValue(sField, vtFld))
	//{
	//	return -2;
	//}
	//_tcscpy(EleInfo.sSpark, (TCHAR*)(_bstr_t)vtFld);

	//sField = _T("SPECIFICATIONS");
	//if (!m_pRs->GetFieldValue(sField, vtFld))
	//{
	//	return -2;
	//}
	//_tcscpy(EleInfo.sSpecifications, (TCHAR*)(_bstr_t)vtFld);

	//EleInfo.iState = ElectState::WaitDetect;

	return 1;
#endif

}

bool EAtmCommonFunction::GetProgramme(CString elecName)
{

	CString filename, output, modelname, filenameWithExt;
	/*for (int i = 0; i < 2; i++ )
	{
	AfxExtractSubString(output, elecName, i, '-');
	filename += output;
	filename += (CString)"-";
	}
	AfxExtractSubString(modelname, elecName, 0, '-');
	filename=filename.Left(filename.GetLength()-1);
	filenameWithExt = filename + (CString)".PRG";
	CString sourcePath, targetPath,sourceFile, targetFile;
	targetPath = "D:\\CMM\\PRG";
	targetFile.Format("%s\\%s", targetPath, filenameWithExt);*/

	filename = GetConnectionParameter(INSPECTIONROOTDIRECTORY) + _T("\\") + elecName + _T("\\") + _T("inspection"); //IO卡版本用的是inspection文件, TCP版直接传递包含inspection文件的 文件夹 elecName
																														 //filename = EAtm.GetConnectionParameter(INSPECTIONROOTDIRECTORY) + _T("\\") + elecName;
	CFileFind tempFind;
	BOOL IsFinded = tempFind.FindFile(filename); //找到了返回 TRUE
	if (IsFinded != TRUE) //,没找到
	{
		return false;
	}
	//CopyFile((LPCSTR)sourceFile, (LPCSTR)targetFile,FALSE);
	return true;
}